package com.lebang.service.sdk.impl;

import com.lebang.domain.SdkTaskMdgg;
import com.lebang.example.SdkTaskMdggExample;
import com.lebang.mapper.SdkTaskMdggMapper;
import com.lebang.model.Whether;
import com.lebang.service.BaseService;
import com.lebang.service.sdk.SdkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDateTime;

import static com.lebang.model.enums.buss.TaskCategory.MDGG;

/**
 * @Author: hwq
 * @Date: 2019/12/5 11:57
 * @Version 1.0
 */
@Service
public class MgddServiceImpl extends BaseService<SdkTaskMdgg, Long, SdkTaskMdggExample> implements SdkService<SdkTaskMdgg> {
    @Autowired
    private SdkTaskMdggMapper sdkTaskMdggMapper;

    public static final String AD_KEY = "1b01bc4b713f2ec";
    /**
     * 验证订单号是否存在
     *
     * @param order
     * @return
     */
    @Override
    public boolean checkOrderNum(String order) {
        return sdkTaskMdggMapper.selectByOrder(order)>0;
    }

    /**
     * 添加订单记录
     *
     * @param orderId  订单号 (唯一)
     * @param type     类型(1金币2钱)
     * @param money    奖励值
     * @param event    奖励说明
     * @param memberId 用户id
     * @param request  请求的消息
     * @return
     */
    @Override
    public boolean insertOrder(String orderId, Integer type, Integer money, String event,  String memberId, String request, BigDecimal myMoney) {
        SdkTaskMdgg record = new SdkTaskMdgg();
        record.setHasDeleted(Whether.NO.getDbIndex());
        record.setCreateTime(LocalDateTime.now());
        record.setModifyTime(LocalDateTime.now());
        record.setMoney(new BigDecimal(money));
        record.setEvent(event);
        record.setMemberId(memberId);
        record.setSdkId(MDGG.name());
        record.setOrderNum(orderId);
        record.setAppId("xianyu");
        record.setMyMoney(myMoney);
        record.setParam(request);
        record.setType(type);
        return this.insertModel(record)>0;
    }

    /**
     * 获取秘钥
     *
     * @return
     */
    @Override
    public String getKey() {
        return AD_KEY;
    }
}
